package com.ysd.twocrm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ysd.twocrm.entity.Weekbook;
import com.ysd.twocrm.mapper.WeekbookMapper;
import com.ysd.twocrm.service.WeekBookService;
import com.ysd.twocrm.utils.LayuiUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.List;
@Service
public class WeekBookServiceImpl implements WeekBookService {
    @Autowired
    private WeekbookMapper weekbookMapper;
    @Override
    public LayuiUtils<Weekbook> LAYUI_UTILS(Weekbook wk, Integer page, List<Integer> userid) {
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        QueryWrapper<Weekbook> queryWrapper=new QueryWrapper<Weekbook>();
        queryWrapper.in("userId",userid);
        if(wk.getWbegintime()!=null){
            queryWrapper.like("wbegintime",sdf.format(wk.getWbegintime()));
        }
        if(wk.getWendtime()!=null){
            queryWrapper.like("wendtime",sdf.format(wk.getWendtime()));
        }
        if(wk.getWstatus()!=null){
            queryWrapper.eq("wstatus",wk.getWstatus());
        }

        Page<Weekbook> weekbookPage=new Page<Weekbook>(page,10);
        LayuiUtils<Weekbook> layuiUtils=new LayuiUtils<Weekbook>();
        Page<Weekbook> weekbookPage1 = weekbookMapper.selectPage(weekbookPage, queryWrapper);
        layuiUtils.setData(weekbookPage1.getRecords());
        layuiUtils.setCount(weekbookPage1.getTotal());
        return layuiUtils;
    }
}
